package cn.tiger.starter.poi;

import cn.tiger.entity.User;
import org.apache.poi.ss.usermodel.*;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.ArrayList;

/**
 * @Author ： ZAG WELL
 * @Date : 2021/5/4
 */
public class POIImport {
    public static void main(String[] args) throws IOException {
        File file = new File("C:\\Users\\ZAG WELL\\Desktop\\测试导出导出\\test.xlsx");
        FileInputStream stream = new FileInputStream(file);
        Workbook workBook = new XSSFWorkbook(stream);
        Sheet sheet = workBook.getSheetAt(0);
        ArrayList<User> users = new ArrayList<>();
        //循环行
        for (int i = 1; i < sheet.getLastRowNum(); i++) {
            User user = new User();
            sheet.getRow(i).getCell(0).setCellType(CellType.STRING);
            user.setAccount(sheet.getRow(i).getCell(0).getStringCellValue());
            sheet.getRow(i).getCell(1).setCellType(CellType.STRING);
            user.setUser(sheet.getRow(i).getCell(1).getStringCellValue());
            sheet.getRow(i).getCell(2).setCellType(CellType.STRING);
            user.setPassword(sheet.getRow(i).getCell(2).getStringCellValue());
            users.add(user);
        }
        for (User user : users) {
            System.out.println(user);
        }


    }
}
